<script setup>
import iconCircle from '../../assets/icons/icon_logo_circle.png'
import iconClose from '../../assets/icons/icon_close.png'

defineProps({
  show: Boolean,
  article: {type: Object, required: true}
})
const emit = defineEmits(['onClose'])
</script>

<template>
  <transition name="fade">
    <view class="column article-popup fadeIn" v-if="show">
      <view class="row popup-header" @click="emit('onClose')">
        <img :class="iconClose" :src="iconClose" alt="" width="20px" height="20px"/>
      </view>
      <view class="popup-content">
        <view class="title">{{ article.title }}</view>
        <view class="author">{{ article.date }} | By {{ article.category }}</view>
        <img class="logo" :src="iconCircle" alt=""/>
        <view class="column item" v-for="(item,index) in article.content" :key="index">
          <img v-if="item.image" class="image" :src="item.image" alt=""/>
          <div v-if="item.p" v-html="item.p" class="paragraph top2"/>
          <div v-if="item.desc" v-html="item.desc" class="desc"/>
        </view>
      </view>
    </view>
  </transition>
</template>

<style scoped>
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter, .fade-leave-to /* .fade-leave-active in <2.1.8 */
{
  opacity: 0;
}

.article-popup {
  width: 100%;
  height: 100%;
  z-index: 20;
  background-color: black;
  position: fixed;

  .popup-header {
    height: 2em;

    img {
      margin-left: auto;
      margin-right: 10px;
      margin-top: 6px;
      align-items: center;
      justify-content: center;
      justify-items: center;
    }
  }

  .popup-content {
    height: 100%;
    overflow-y: scroll;
    background-color: white;
    border-radius: 12px 12px 0 0;
    color: black;
    padding: 4% 8.3%;
    display: flex;
    flex-direction: column;

    .title {
      font-size: 2.66em;
      margin: 0 auto;
    }

    .author {
      text-align: center;
      color: #9E9EA2;
      margin-top: 2em;
    }

    .logo {
      margin: 1em auto;
      width: 3.8em;
    }

    .item {
      margin-top: 10px;

      .image {
        max-width: 70%;
        margin: 0 auto;
        border-radius: 12px;
      }

      .paragraph {
        font-weight: 300;
      }

      .desc {
        color: #333333;
        font-size: 0.8em;
        white-space: pre-line;
        margin-top: 1em;
        margin-bottom: 0.5em;
      }
    }

    .from {
      font-size: 0.8em;
      color: #9E9EA2;
      margin-top: 3em;
    }
  }
}
</style>